Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Proposed changes for multi-testnet faucet option #32

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cooganb
Copy link
Contributor

@cooganb cooganb commented May 17, 2021

Hey there, two main changes:

  • The first is on the webapp side, where it's mainly about providing a valid etherscan URL that's not just ropsten
  • The second is proposed changes on server file, showing where I think the indicated network will be.

I'm not familiar enough with the codebase or ethQuery to make the best decision about this, but will message you on slack as well.

The other thing I'm stuck on is the best way to encode which network the user wants when sending the POST request -- it could either be stuck onto the front of the rawdata string that's parsed, or the webapp can format the req into a JSON. but I think parsing a JSON on the server side might be a little too weird, but you would know best.

@cooganb cooganb requested a review from a team as a code owner May 17, 2021 01:33
@cooganb cooganb marked this pull request as draft May 17, 2021 11:09
@@ -85,6 +87,11 @@ function startServer () {
async function handleRequest (req, res) {
try {
// parse address
// can parse for network here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server must have an explicit allowlist (not a denylist) for network ids it permits to send from. that faucet occasionally accidentally holds real world assets on mainnet and bsc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kumavis Got it, what does that mean for the parsing here?

// can either be json object or
// inserted in a combined rawdata string with address, and then parsed out here
// depending on what the network is, make sure ethQuery engine knows when
// testing balance and sending transaction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go with json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

const balance = await ethQuery.getBalance(targetAddress, 'pending')
const balanceTooFull = balance.gt(MAX_BALANCE)
if (balanceTooFull) {
console.log(`${requestorMessage} - already has too much ether`)
return didError(res, new Error('User is greedy - already has too much ether'))
}
// send value
// need ot change network here as well:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we're currently doing eip155 sigs here, we should fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also going to need infura api keys for each network

@kumavis I don't think we will if we're using Infura the way it normally is. As you can see here, you can change the Ethereum network from an Infura API simply by changing the subdomain:

Screen Shot 2021-06-07 at 3 39 11 PM

Screen Shot 2021-06-07 at 3 39 03 PM

The one issue I'm having is how to dynamically change rpcUrl of the engine based on user's request. The relevant code is here:

https://github.com/ConsenSys-Academy/eth-faucet/blob/07dc818c341b2103175420295c068f25278a0e58/src/server/index.js#L40

Do you have any ideas of how to do this?

@@ -36,6 +36,8 @@ console.log('Acting as faucet for address:', config.address)
//

// ProviderEngine based caching layer, with fallback to geth
//
// need to be able to dynamically change rpcOrigin based on network requesting funds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the provider stack is quite, old it should be replace by https://github.com/MetaMask/eth-json-rpc-middleware and the json-rpc-engine stack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the provider stack is quite, old it should be replace by https://github.com/MetaMask/eth-json-rpc-middleware and the json-rpc-engine stack

@kumavis Will that change the syntax here much?

@@ -232,16 +253,18 @@ async function getEther () {
if (!account) return

var uri = `${window.location.href}v0/request`
var data = account
var data = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may have to json serialize this first. verify that the fetch api supports providing an object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kumavis just a quick search makes it seem like I may have to use JSON.stringify(), does that sound right?

@kumavis
Copy link
Member

kumavis commented Jun 4, 2021

you should also checkout https://github.com/MetaMask/test-dapp/ and see if it meets your needs

@kumavis
Copy link
Member

kumavis commented Jun 4, 2021

also going to need infura api keys for each network

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants